
#pragma once
#include<pthread.h>
using namespace std;
#include"MyMute.hpp"
using namespace MyMutexModule;

namespace MyCondModule
{
    class Cond
    {
    public:
        Cond()
        {
            pthread_cond_init(&_cond,nullptr);
        }

        //要让线程释放曾经拥有的锁！！
        void wait(Mutex& mutex)
        {
            int n = pthread_cond_wait(&_cond,mutex.getAddr());
            (void)n;
        }

        void signal()
        {
            int n = pthread_cond_signal(&_cond);
            (void)n;
        }

        void signalAll()
        {
            int n = pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~Cond()
        {
            pthread_cond_destroy(&_cond);
        }
    private:
        pthread_cond_t _cond;
    };
}